package cn.com.taiji.pos.mapper;

import cn.com.taiji.pos.entity.CardAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 账户信息 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
public interface CardAccountMapper extends BaseMapper<CardAccount> {

    @Select("select ca.ID,ca.AMOUNT,ca.TIMES,cat.SORT_NO as catSortNo,cmt.ID as mealTimeId,cmt.Name as cmtName,cat.ID as accountTypeId,sdd.NAME as sddName,cat.NAME as catName " +
            "from CARD_CUSTOMER cc inner JOIN card_customer_type cct on cc.CUSTOMER_TYPE_ID = cct.id " +
            "inner join CARD_ACCOUNT ca on  cc.ID=ca.CUSTOMER_ID  " +
            "inner join CARD_ACCOUNT_TYPE cat on ca.ACCOUNT_TYPE_ID =cat.ID " +
            "inner  JOIN   config_meal_time cmt on ca.MEAL_TIME_ID=cmt.ID " +
            "inner join system_dict_data sdd on cat.ACCOUNT_CATEGORY_ID=sdd.ID " +
            "where cc.ID=#{arg0} and cct.Status<>1 and cat.Status<>1 and cc.Status<>1 and ca.Status<>1 and cmt.NAME=#{arg1} order by cat.SORT_NO ASC")
    List<CardAccount> findCardAccountList(String customerId, String canci);


    @Select("select ca.ID,ca.AMOUNT,ca.TIMES,cat.SORT_NO as catSortNo,cmt.ID as mealTimeId,cmt.Name as cmtName,cat.ID as accountTypeId,sdd.NAME as sddName,cat.NAME as catName " +
            "from CARD_CUSTOMER cc inner JOIN card_customer_type cct on cc.CUSTOMER_TYPE_ID = cct.id " +
            "inner join CARD_ACCOUNT ca on  cc.ID=ca.CUSTOMER_ID  " +
            "inner join CARD_ACCOUNT_TYPE cat on ca.ACCOUNT_TYPE_ID =cat.ID " +
            "left JOIN config_meal_time cmt on ca.MEAL_TIME_ID=cmt.ID " +
            "inner join system_dict_data sdd on cat.ACCOUNT_CATEGORY_ID=sdd.ID " +
            "where cc.ID=#{arg0} and cct.Status<>1 and cat.Status<>1 and cc.Status<>1 and ca.Status<>1 and cmt.NAME is null order by cat.SORT_NO ASC")
    List<CardAccount> findCardAccountList2(String customerId);


    @Select("select ca.ID,ca.AMOUNT,ca.TIMES,cat.SORT_NO as catSortNo,cat.ID as accountTypeId,sdd.NAME as sddName,cat.NAME as catName,cct.id as cctID,cc.ID as customerId " +
            "from CARD_CUSTOMER cc inner JOIN card_customer_type cct on cc.CUSTOMER_TYPE_ID = cct.id " +
            "inner join CARD_ACCOUNT ca on  cc.ID=ca.CUSTOMER_ID  " +
            "inner join CARD_ACCOUNT_TYPE cat on ca.ACCOUNT_TYPE_ID =cat.ID " +
            "inner join system_dict_data sdd on cat.ACCOUNT_CATEGORY_ID=sdd.ID " +
            "where cc.ID=#{arg0} and cct.Status<>1 and cat.Status<>1 and cc.Status<>1 and ca.Status<>1 order by cat.SORT_NO ASC")
    List<CardAccount> findCardAccountList3(String customerId);
}
